//
//  ALFirstTableViewCell.m
//  Ummy.G
//
//  Created by 安林 on 16/9/28.
//  Copyright © 2016年 安林. All rights reserved.
//

#import "ALFirstTableViewCell.h"
#import "ALButton.h"

//屏幕的宽
#define ALW self.frame.size.width

@implementation ALFirstTableViewCell

- (void)awakeFromNib {
    self.scrollView.delegate=self;
    self.scrollView.backgroundColor=[UIColor clearColor];
    self.scrollView.contentSize = CGSizeMake(2 * ALW , 0 );//设置scrollView的大小
   self.scrollView.pagingEnabled=YES;
    //删除下面的滚动条
    self.scrollView.showsHorizontalScrollIndicator=NO;
   
    //第一个小scrollView页面
    _view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ALW, self.scrollView.bounds.size.height)];
    _view1.backgroundColor = [UIColor clearColor];
    [self.scrollView addSubview:_view1];
    
    //第二个小scrollView页面
    _view2=[[UIView alloc]initWithFrame:CGRectMake(ALW, 0, ALW, self.scrollView.bounds.size.height)];
    _view2.backgroundColor = [UIColor clearColor];
    [self.scrollView addSubview:_view2];

    
    //设置小圆点
    _pageControl = [[UIPageControl alloc]init];
    _pageControl.frame = CGRectMake(ALW/2-31, 165, 5, 2);
   self.pageControl.currentPage = 0;//小圆点的当前页
    self.pageControl.numberOfPages = 2;//总共有多少个小圆点
    self.pageControl.currentPageIndicatorTintColor = ALColor(0, 201, 177);//小圆点当前的颜色
    
    self.pageControl.pageIndicatorTintColor=[UIColor lightGrayColor];//其他小圆点的颜色
    [self addSubview:self.pageControl];

    
    _arrImage =@[@"icon_homepage_foodCategory",@"icon_homepage_movieCategory",@"icon_homepage_hotelCategory",@"icon_homepage_entertainmentCategory",@"icon_homepage_shoppingCategory",@"icon_homepage_beautyCategory",@"icon_homepage_foottreatCategory",@"icon_homepage_KTVCategory",@"icon_homepage_lifeServiceCategory",@"icon_homepage_default"];
    _arrTitle=@[@"美食",@"电影",@"酒店",@"休闲娱乐",@"购物",@"丽人",@"足疗按摩",@"KTV",@"母婴亲子",@"景点"];

    [self addButton];
    
    
}

#pragma mark 加载上面的十个按钮
- (void)addButton{

    //设置每行多少列
    int column =5;
    
    //设置间距
    CGFloat margin =22;//按钮和左面的距离
    CGFloat margin1 =25;//两个按钮之间的距离
    CGFloat top = 10;//按钮离顶端的距离
    CGFloat buttonW = (UIScreenW-2*margin1-(column-1)*margin1)/5.0;
    CGFloat buttonH = buttonW;
    for (int i =0; i<self.arrImage.count; i++) {
//------------第一页的按钮-----------------
        //按钮的样式
        ALButton *button = [ALButton buttonWithType:UIButtonTypeCustom];
        //按钮的标题
        [button setTitle:self.arrTitle[i] forState:UIControlStateNormal];
        //按钮的图片
        [button setImage:[UIImage imageNamed:self.arrImage[i]] forState:UIControlStateNormal];
        CGFloat x =i%column;
        CGFloat y =i/column;
        button.frame =CGRectMake(margin+(buttonW+margin1)*x, top+(margin+buttonW)*y+20*y+15, buttonW, buttonH);//每一个按钮的位置
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];//给按钮添加单击事件
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//按钮上字体的颜色
        
        [self.view1 addSubview:button];
        
//--------------第二页的按钮----------------
        //按钮的样式
        ALButton *button2 = [ALButton buttonWithType:UIButtonTypeCustom];
        //按钮的标题
        [button2 setTitle:self.arrTitle[i] forState:UIControlStateNormal];
        //按钮的图片
        [button2 setImage:[UIImage imageNamed:self.arrImage[i]] forState:UIControlStateNormal];
        CGFloat x2 =i%column;
        CGFloat y2 =i/column;
        button2.frame =CGRectMake(margin+(buttonW+margin1)*x2, top+(margin+buttonW)*y2+20*y2+15, buttonW, buttonH);//每一个按钮的位置
        [button2 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];//给按钮添加单击事件
        [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//按钮上字体的颜色
        
        [self.view2 addSubview:button2];


    }
}

//多个按钮监听一个方法，最好有一个参数
- (void)click:(UIButton *)sender{
    
}


#pragma mark 让小圆点滚动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
        //获取在x轴上的移动距离
    CGFloat distance = self.scrollView.contentOffset.x;
    int num = distance / ALW;
    self.pageControl.currentPage = num;
    
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

#pragma mark 让xib显示出来
+(instancetype)loadALFirstTableViewCell{
    return [[[NSBundle mainBundle]loadNibNamed:@"ALFirstTableViewCell" owner:nil options:nil]firstObject];
}


@end
